000100* FUNCTION : CBU-batch-mode
000200* FILE : CBUP0005[.CBL]
000300 IDENTIFICATION DIVISION.
000400 PROGRAM-ID. CBUP0005.
000500 ENVIRONMENT DIVISION.
000600 INPUT-OUTPUT SECTION.
000700 FILE-CONTROL.
000800* <MVS>
000900*      SELECT BATCHCMD ASSIGN TO UT-S-CBUBATCH.
      * </MVS>
001000* <WIN>
001100    SELECT BATCHCMD ASSIGN TO "CBUBATCH.DAT"
001200     ORGANIZATION IS LINE SEQUENTIAL.
      * </WIN>
001300 DATA DIVISION.
001400 FILE SECTION.
001500 FD  BATCHCMD BLOCK 0.
001600 01  CMDrecord       PIC X(80).
001700
001800 WORKING-STORAGE SECTION.
001900
002000* COPYBOOK USED FOR CALLING COBOLUNIT MAIN ROUTINE CBUP0001
002100*
002200     COPY CBUC0001.
002300
002400* COPYBOOK DESCRIBING ALL CBU-functions with their "nicknames"
002500
002600     COPY CBUC0003.
002700
002800* VARIABLES USED IN THE STRING MANIPULATION ROUTINES
002900
003000     COPY CBUC00W6.
003100     COPY CBUC0004.
003200
003300* PROGRAM VARIABLES
003400
003500 01  INPUT-FILE-STATUS           PIC X          VALUE SPACE.
003600     88 IFS-NOT-OPEN                            VALUE SPACE.
003700     88 IFS-OPEN                                VALUE "O".
003800     88 IFS-END                                 VALUE "E".
003900
004000 01  SYSIN                        PIC X(80).
004100 01  RES-LANG                     PIC X(2)      VALUE "EN".
004200 01  RES-AREA.
004300     05  RES-NAME                    PIC X(20).
004400     05  RES-DESC                    PIC X(100).
004500     05  RES-PROG                    PIC X(8).
004600     05  RES-KEYWORD                 PIC X(20).
004700     05  RES-KEYVALUE                PIC X(60).
           05  RES-MSG                     PIC X(80).
004800
004900
005000 01  INI-IND1                    PIC S9(4) COMP VALUE 0.
005100 01  INI-IND2                    PIC S9(4) COMP VALUE 0.
005200 01  INI-IND3                    PIC S9(4) COMP VALUE 0.
005300 01  INI-NB                      PIC S9(4) COMP VALUE 0.
005400 01  INI-DATA.
005500     05 INI-LINE                 OCCURS 2000.
005600        10 INI-TYPE              PIC X.
005700        10 INI-VALUE.
005800           15 INI-KEYWORD        PIC X(20).
005900           15 INI-KEYVALUE       PIC X(60).
006000
006100 01  MAX-RETURN-CODE             PIC X          VALUE SPACE.
006200
006300 PROCEDURE DIVISION.
006400
006500 mainline.
006600
006700* 1st STEP : the batch command file is read, checked and stored
006800* in an array
006900
007000     PERFORM IFS-READ.
007100     PERFORM UNTIL IFS-END
007200        PERFORM IFS-PROCESS
007300        PERFORM IFS-READ
007400     END-PERFORM.
007500
007600* 2nd STEP : the commands are executed by calling CBU-main
007700*
007800     MOVE SPACE TO RES-AREA.
007900     PERFORM VARYING INI-IND1 FROM 1 BY 1 UNTIL INI-IND1 > INI-NB
008000        IF INI-TYPE (INI-IND1) = "*"
008100           THEN CONTINUE
008200           ELSE PERFORM PROCESS-KEYWORD
008210        END-IF
008300     END-PERFORM.
008400
008500     IF MAX-RETURN-CODE = " "
008600        MOVE 0 TO RETURN-CODE
008700        ELSE IF MAX-RETURN-CODE = "W"
008800                MOVE 4 TO RETURN-CODE
008900                ELSE IF MAX-RETURN-CODE = "E"
009000                        MOVE 8 TO RETURN-CODE
009100                     ELSE MOVE 12 TO RETURN-CODE
009200                     END-IF
009300             END-IF
009400     END-IF.
009500     GOBACK.
009600
009700 IFS-READ.
009800     IF IFS-NOT-OPEN THEN
009900         OPEN INPUT BATCHCMD
010000         SET IFS-OPEN TO TRUE
010100     END-IF.
010200
010300     READ BATCHCMD NEXT RECORD INTO SYSIN
010400        AT END
010500           CLOSE BATCHCMD
010600           SET IFS-END TO TRUE.
010700
010800 IFS-PROCESS.
010900
011000     MOVE SYSIN TO STRING-TO-STRIP
011100     PERFORM STRIP-A-STRING
011200     IF STRIP-LENGTH = 1 AND STS (STRIP-BEG) = SPACE
011300        CONTINUE
011400        ELSE
011500        MOVE STRING-TO-STRIP (STRIP-BEG : STRIP-LENGTH)
011600        TO STRING-TO-STRIP
011700        IF STS (1) = "*"
011800           ADD 1 TO INI-NB
011900           MOVE STRING-TO-STRIP TO INI-LINE (INI-NB)
012000        ELSE
012100           IF STS (1) = "<"
012200              PERFORM VARYING INI-IND1 FROM 1 BY 1
012300              UNTIL INI-IND1 > STRIP-LENGTH
012400              OR STS (INI-IND1) = ">"
012500                 CONTINUE
012600              END-PERFORM
012700              IF STS (INI-IND1) = ">"
012800                 ADD 1 TO INI-NB
012900                 MOVE "K" TO INI-TYPE (INI-NB)
013000                 MOVE STRING-TO-STRIP (1 : INI-IND1)
013100                 TO INI-KEYWORD (INI-NB)
013200                 ADD 1 TO INI-IND1 GIVING INI-IND2
013300                 COMPUTE INI-IND3 = STRIP-LENGTH - INI-IND1
013400                 MOVE STRING-TO-STRIP (INI-IND2 : INI-IND3)
013500                 TO STRING-TO-STRIP
013600                 PERFORM STRIP-A-STRING
013700                 MOVE STRING-TO-STRIP (STRIP-BEG : STRIP-LENGTH)
013800                 TO INI-KEYVALUE (INI-NB)
013900              ELSE
014000                 PERFORM UNDEFINED-INI-LINE
014100              END-IF
014200           ELSE
014300              PERFORM UNDEFINED-INI-LINE
014400           END-IF
014500        END-IF
014600     END-IF.
014700
014800
014900
015000 UNDEFINED-INI-LINE.
015100
015200     DISPLAY "EN111 UNDEFINED INI LINE" SYSIN .
015300     IF MAX-RETURN-CODE = " " OR "W" MOVE "E" TO MAX-RETURN-CODE.
015400
015500 PROCESS-KEYWORD.
015600     MOVE INI-KEYWORD (INI-IND1) TO RES-KEYWORD
015700     MOVE INI-KEYVALUE (INI-IND1) TO RES-KEYVALUE
015800     EVALUATE TRUE
015900
016000* STORE INFORMATION FOR FURTHER PROCESSING
016100        WHEN RES-KEYWORD = "<SETNAME>"
016200           MOVE RES-KEYVALUE TO RES-NAME
016300        WHEN RES-KEYWORD = "<SETDESC>"
016400           MOVE RES-KEYVALUE TO RES-DESC
016500        WHEN RES-KEYWORD = "<SETPROG>"
016600           MOVE RES-KEYVALUE TO RES-PROG
016700        WHEN RES-KEYWORD = "<SETLANG>"
016800           MOVE RES-KEYVALUE TO RES-LANG
016900
017000* PROCESS CBU Command
017100        WHEN RES-KEYWORD = "<RESETRUN>"
017400           CALL CBU-main
017500              USING CBU-reset-run CBU-MAIN-CALL-INTERFACE
017600           PERFORM UPDATE-RET-CODE
017100        WHEN RES-KEYWORD = "<INIT>"
                 MOVE SPACE TO MAX-RETURN-CODE
017400           CALL CBU-main
017500              USING CBU-initialize CBU-MAIN-CALL-INTERFACE
017600           PERFORM UPDATE-RET-CODE
017100        WHEN RES-KEYWORD = "<ADDSUITE>"
017200           MOVE RES-NAME TO CBU-SUITE-NAME
017300           MOVE RES-DESC TO CBU-SUITE-DESCRIPTION
017400           CALL CBU-main
017500              USING CBU-add-suite CBU-MAIN-CALL-INTERFACE
017100        WHEN RES-KEYWORD = "<PRTMSG>"
017200           MOVE RES-KEYVALUE TO CBU-USER-MESSAGE
017400           CALL CBU-main
017500              USING CBU-print-user-msg CBU-MAIN-CALL-INTERFACE
017600           PERFORM UPDATE-RET-CODE
017700        WHEN RES-KEYWORD = "<ADDTEST>"
017800           MOVE RES-NAME TO CBU-TEST-NAME
017900           MOVE RES-DESC TO CBU-TEST-DESCRIPTION
018000           MOVE RES-PROG TO CBU-TEST-PROG-NAME
018100           CALL CBU-main
018200              USING CBU-add-test-next CBU-MAIN-CALL-INTERFACE
018300           PERFORM UPDATE-RET-CODE
018400        WHEN RES-KEYWORD = "<RUN>"
018500           IF MAX-RETURN-CODE = " " OR "W"
018600               CALL CBU-main USING CBU-run CBU-MAIN-CALL-INTERFACE
018700               PERFORM UPDATE-RET-CODE
018800           ELSE DISPLAY "TOO MANY ERRORS ENCOUNTERED"
018900               " EXECUTION PHASE CAN'T BE RUN."
019000           END-IF
019100
019200* ERROR
019300        WHEN OTHER
019400           PERFORM INVALID-KEYWORD
019500     END-EVALUATE.
019600
019700 INVALID-KEYWORD.
019800
019900     DISPLAY " INVALID KEYWORD" RES-KEYWORD RES-KEYVALUE.
020000     IF MAX-RETURN-CODE = " " OR "W" MOVE "E" TO MAX-RETURN-CODE.
020100
020200 UPDATE-RET-CODE.
020300     EVALUATE TRUE
020400        WHEN CBU-WARNING
020500             AND MAX-RETURN-CODE = " "
020600                MOVE CBU-EXECUTION-RETURN-CODE TO MAX-RETURN-CODE
020700        WHEN CBU-ERROR
020800             AND (MAX-RETURN-CODE = " " OR "W")
020900                MOVE CBU-EXECUTION-RETURN-CODE TO MAX-RETURN-CODE
021000        WHEN CBU-SEVERE
021100             AND (MAX-RETURN-CODE = " " OR "W" OR "E")
021200                MOVE CBU-EXECUTION-RETURN-CODE TO MAX-RETURN-CODE
021300        WHEN OTHER CONTINUE
021400     END-EVALUATE.
021500
021600 CALLPRINT.
021700
021800* PRINT CURRENT LINE
021900     MOVE RES-LANG TO CBU-MSG-LG
022000     CALL CBU-log-print USING CBU-LOG-PRINT-INTERFACE
022100* RESET DEFAULTS
022200     SET CBU-PRINT-A-LINE TO TRUE
022300     SET CBU-PRINT-ON-NEXT-LINE TO TRUE
022400     INITIALIZE CBU-MESSAGE-TO-PRINT.
022500
022600* INCLUDE STRING MANIPULATION ROUTINES
022700     COPY CBUC00P6.
